* Reset settings and initialize log file
launch, path("share/unpaid_leave")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show seasonal movements in paid vs. unpaid absences.
*-------------------------------------------------------------------------------


* Prepare data and run models
*-------------------------------------------------------------------------------

if "$estimate" != "0" {
	* Load sample
	gzuse "$basepath/data/derived/cps_bms_sample.dta.gz", clear

	* Restrict to years in which leave type is observed
	keep if year >= 1994

	* Indicators for paid absence and unpaid absence
	gen abs_paid = (absent == 1 & paid_absence == 1)
	gen abs_unpaid = (absent == 1 & paid_absence == 0)

	* Aggregate across individuals
	gcollapse (mean) abs_paid abs_unpaid (rawsum) wtfinl (first) month tmspline* weeks [pw = wtfinl], by(female tm)
	tsset female tm

	* Loop over sex
	foreach f of numlist 0 1 {
		* Loop over outcome variables
		foreach yvar of varlist abs_paid abs_unpaid {
			* Run the specification
			quietly ivreg2 `yvar' ib5.month tmspline* weeks if female == `f' [aw = wtfinl], bw($bandwidth) robust small
			process_estimates, path("unpaid_leave") model("f`f'_`yvar'")
		}
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("unpaid_leave")

* Prepare coefficient labels for each month
make_coeflabels


* Plot seasonality in absence type by sex
*-------------------------------------------------------------------------------

* Prepare background shading
clear
set obs 14
gen rlow = -1.0
gen rupp = +4.0
gen rval = _n - 0.5

* Plot estimates
foreach f of numlist 0 1 {
	if `f' == 0 {
		local flbl "Men"
	}
	else if `f' == 1 {
		local flbl "Women"
	}

	#delimit ;
	coefplot
		(f`f'_abs_paid, offset(-.05) recast(connected) label("Paid absence"))
		(f`f'_abs_unpaid, offset(+.05) recast(connected) label("Unpaid absence")),
		coeflabels(`coeflabels')
		title("{bf:`flbl'}")
		xtitle("")
		xlabel(, alternate)
		ytitle("")
		yscale(range(-1 4))
		ylabel(-1(1)4)
		addplot(
			rarea rupp rlow rval if inrange(rval, 0.5, 5.5), color($ltgs) plotregion(margin(t=0 b=0)) below ||
			scatteri 0 0.5 0 13.5, recast(line) color(black) below)
		vertical
		legend(rows(1) size(*0.8) order(4 6))
		rescale(100);
	#delimit cr

	tempfile g`f'
	graph save "`g`f''"
}

* Create two-panel figure
grc1leg "`g1'" "`g0'", l1title("     Difference relative to May (p.p.)", size(*.8)) imargin(vsmall)
nicepdf "$basepath/output/unpaid_leave.pdf", panels(2) indirect replace

* Close the log file
unlaunch
